package com.fyzk.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.TextView;

import com.fyzk.net.PublicMethod;
import com.tyjc.lottery.R;

/**
 * <p>
 *
 * @author 指尖沙漏
 * @mood
 * @description
 * @date 2019/9/24 11:20
 * </p>
 */
public class TransformDialog extends Dialog implements View.OnClickListener {
    private Context mContext;
    private OnCloseListener listener;
    private String title;
    private long transformMoney;
    private long addMoney;
    private long oldMoney;
    private long newMoney;

    private TextView tvTitle;
    private TextView tvRemind1;
    private TextView tvRemind2;
    private TextView tvRemind3;
    private TextView tvSubmit;

    public TransformDialog(Context context, OnCloseListener listener, long transformMoney, long oldMoney, long newMoney) {
        super(context, R.style.commonDialog);
        this.mContext = context;
        this.listener = listener;
        this.transformMoney = transformMoney;
        this.oldMoney = oldMoney;
        this.newMoney = newMoney;
    }

    public TransformDialog setTitle(String title) {
        this.title = title;
        return this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_transform);
        initView();
        initData();
    }

    private void initView() {
        tvTitle = findViewById(R.id.title);
        tvRemind1 = findViewById(R.id.remind1);
        tvRemind2 = findViewById(R.id.remind2);
        tvRemind3 = findViewById(R.id.remind3);
        tvSubmit = findViewById(R.id.submit);
        tvSubmit.setOnClickListener(this);
    }

    private void initData() {
        tvTitle.setText(title);
        addMoney = newMoney - oldMoney;
        tvRemind1.setText(Html.fromHtml("1.您已成功转换彩金：<font color='#FD4A4A'>"
                + PublicMethod.formatBalance(transformMoney) + "米</font>"));
        tvRemind2.setText(Html.fromHtml("2.成功获得赠送彩金：<font color='#FD4A4A'>"
                + PublicMethod.formatBalance(addMoney) + "米</font>"));
        tvRemind3.setText(Html.fromHtml("3.您的可用彩金由：<font color='#FD4A4A'>"
                + PublicMethod.formatBalance(oldMoney) + "米</font>变为<font color='#FD4A4A'>"
                + PublicMethod.formatBalance(newMoney) + "米</font>"));
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.submit:
                if (listener != null) {
                    listener.onClick(this, true);
                }
                dismiss();
                break;
        }
    }

    public interface OnCloseListener {
        void onClick(Dialog dialog, boolean confirm);
    }

}


